﻿using Microsoft.PointOfService;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace POS
{
    class StaticProperties
    {
        public static string FileLocation = Environment.CurrentDirectory + "\\";
        public static string FileName = "Startup.xml";
        public static string TableChartFileName = "SeatingChart.xml";
        public static string SQLServerIP { get; set; }
        public static string SQLServerPORT { get; set; }
        public static string myConnectionString { get; set; }
        public static double TimeToUpdate { get; set; }

        public static string connectionstring()
        {
            return "Data Source=" + SQLServerIP + "," + SQLServerPORT + ";Network Library=DBMSSOCN;Initial Catalog=RabbitPosSoftware;User ID=sa;Password=502370;";
        }


        public static string TableChartXML { get; set; }

        public static void GetTableChartXML()
        {
            
            using (StreamReader reader = new StreamReader(FileLocation + TableChartFileName))
            {
                TableChartXML = reader.ReadToEnd();//.ReadLine();
            }
        }

        public static Msr CreditCardReader;
        public static PosPrinter StationPrinter;

        public static void LoadPeripherals()
        {
            try
            {
                SplashScreen1._main.labelControl2.Text = "Loading Card Reader".ToUpper();

                PosExplorer myPosExplorer = new PosExplorer();
                DeviceCollection myDevices;

                myDevices = myPosExplorer.GetDevices();

                foreach (DeviceInfo devInfo in myDevices)
                {
                    //MessageBox.Show(devInfo.ServiceObjectName);

                    if (devInfo.ServiceObjectName == "Microsoft Msr Simulator")
                    {
                        StaticProperties.CreditCardReader = myPosExplorer.CreateInstance(devInfo) as Msr;
                    }
                }
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.ToString());//"UNABLE TO CONNECT TO CARD READER");
            }
        }



        public static int ReceiptNo { get; set; }
        public static string TableName { get; set; }
        public static string ServerName { get; set; }
        public static int ServerID { get; set; }
        public static List<string> EmployeeNamesList = new List<string>();
        public static string EmployeeTitle { get; set; }


        public static bool checkLogin(int UserName, int Password)
        {
            foreach (DataRow row in DataTableClass.EmployeeLogin.Rows) // Loop over the rows.
            {
                if ((row["EmployeeID"].ToString().Trim() == UserName.ToString()) && (row["EmployeePassword"].ToString().Trim() == Password.ToString()))
                {

                    ServerName = row["EmployeeFullName"].ToString().Trim();
                    ServerID = (int)row["EmployeeID"];
                    EmployeeTitle = row["EmployeeTitle"].ToString().Trim();
                    return true;
                }
            }

            return false;
        }

        public static int StartingReceiptNo { get; set; }
        public static int DateCode { get; set; }

        public static void GetDateCode()
        {
            DateTime date = DateTime.Now;
            double datetoOADate = date.ToOADate();


            int i = (int)Math.Truncate(date.ToOADate());

            DateCode = i;
        }

        public static string ReceiptNoGenerator()
        {
            DateTime date = DateTime.Now;
            double datetoOADate = date.ToOADate();


            int i = (int)Math.Truncate(date.ToOADate());

            string ReceiptNumberCombo = i.ToString() + StartingReceiptNo.ToString();
            StartingReceiptNo++;


            return ReceiptNumberCombo;
        }

        public static void GetEmployeeNameList()
        {
            EmployeeNamesList.Clear();

            foreach (DataRow row in DataTableClass.EmployeeLogin.Rows) // Loop over the rows.
            {
                EmployeeNamesList.Add((row["EmployeeFullName"].ToString().Trim()));
            }
        }

    }
}
